package com.dimples.dd.system.controller;

import com.dimples.dd.common.constant.DDServerConstant;
import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.log.core.annotation.ApiLog;
import com.dimples.dd.log.core.enums.OperateTypeEnum;
import com.dimples.dd.system.api.logger.dto.OperateLogCreateReqDTO;
import com.dimples.dd.system.model.query.OperateLogPageQuery;
import com.dimples.dd.system.model.vo.OperateLogPageVO;
import com.dimples.dd.system.service.SystemOperateLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "11.操作日志")
@RestController
@RequestMapping("/operate-log")
@Validated
@RequiredArgsConstructor
public class SysOperateLogController {

    private final SystemOperateLogService operateLogService;

    @GetMapping("/page")
    @Operation(summary = "获得操作日志分页列表")
    @PreAuthorize("@ss.hasPerm('system:operate-log:query')")
    @ApiLog(operateType = OperateTypeEnum.SELECT, applicationName = DDServerConstant.DD_SERVER_SYSTEM, enable = false)
    public PageResult<OperateLogPageVO> selectOperateLogPage(@Valid OperateLogPageQuery pageQuery) {
        return this.operateLogService.selectOperateLogPage(pageQuery);
    }


    @PostMapping
    @Operation(summary = "创建登录日志", hidden = true)
    public void createOperateLog(@Valid @RequestBody OperateLogCreateReqDTO operateLogCreateReqDTO) {
        this.operateLogService.createOperateLog(operateLogCreateReqDTO);
    }

}
